@extends('Admin.base')
@section('css')
    <link rel="stylesheet" href="/Admin/layuiadmin/css/extend/formSelects-v4.css" media="all">
@endsection
@section('style')

@endsection
@section('content')

    <div class="layui-card">
        <div class="layui-card-header layuiadmin-card-header-auto">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>补货详情</legend>
            </fieldset>
        </div>
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item layui-row">
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-table" lay-filter="LAY-table"></table>
            <br><br>
            <table id="Goods" lay-filter="Goods"></table>
            <script type="text/html" id="toolbar">
                <div class="layui-btn-container">
                    <button class="layui-btn" lay-event="export">导 出</button>
                </div>
            </script>
        </div>
    </div>

@endsection
@section('script')
    <script src="/js/ajax.js"></script>
    <script>

        layui.use(['form', 'table', 'formSelects'], function(){
            var $ = layui.$
                    ,form = layui.form
                    ,table = layui.table
            var GoodsTabel = table.render({
                elem: '#Goods'
                ,title: "商品补货详情表"
                ,defaultToolbar: []
                ,width: 600
                ,url: '/admin/store/{{$id}}/padRecordDetailTable'
                ,method: "post"
                ,page: true
                ,limit:10
                ,cols: [[
                    {field: '', width: 150 ,title: '缩略图',templet:function(d){
                        return '<img src="'+ d.goods['photo'] +'" alt="" width="30px" height="30px">';
                    }}
                    ,{field: 'goods_id', title: '商品信息',templet:function(d){
                        return d.goods?  d.goods['title'] + "<br>" + d.goods['sku'] + "<br>" +d.goodsbrand :"";
                    }}
                    ,{field: 'goods_num', title: '补货数量'}
                ]]
            })

            var tableins = table.render({
                elem: '#LAY-table'
                ,title: "商品补货详情表"
                ,toolbar: "#toolbar"
                ,defaultToolbar: []
                ,id: 'list'
                ,width: 1500
                ,url: '/admin/store/{{$id}}/padRecordTableById'
                ,method: "post"
                ,cols: [[
                    {field: 'created_at', title: '日期'}
                    ,{field: 'order_no', title: '补货单号'}
                    ,{field: '', title: '操作人',templet:function(d){
                        return d.adminer['username'];
                    }}
                    ,{field: 'skunum', title: '补货品类'}
                    ,{field: 'amount', title: '补货数量'}
                    ,{field: 'remark', title: '补货事由'}
                ]]
            });
            //监听工具条
            table.on('toolbar(LAY-table)', function(obj){
                var field = obj.config.where;
                if(obj.event === 'export'){//export
                    layer.prompt({
                        formType: 0,
                        value: '',
                        title: '请输入文件名称',
                        btn:['导出','取消']
                    }, function(value, index, elem){
                        if(value == '' || value == undefined){
                            layer.msg('请输入文件名称');
                        }else{
                            field.filename = value;
                            field.id = '{{$id}}';
                            $.ajax({
                                url: '/admin/store/exportdetail'
                                , type: 'POST'
                                , dataType: 'json'
                                , data: field
                                , success: function (ret) {
                                    if (ret.hasOwnProperty('code') && ret.code == 200) {
                                        layer.msg(ret.message,{icon: 1,time:2000});
                                        return false;
                                    }
                                    layer.msg(ret.message,{icon:2});
                                }
                            });
                            layer.close(index);
                        }

                    });
                }

            });
            //监听搜索
            form.on('submit(LAY-search)', function(data){
                var field = data.field;
                console.log(field);
                //执行重载
                table.reload('list', {
                    where: field,page: {curr: 1}
                });

            });
        });
    </script>

@endsection